<?php
$this->pageTitle = 'Pridať osobu';
?>
<div class="newForm">
	<h3>Pridať osobu</h3>
	<?php echo $this->Form->create('Person'); ?>
		<fieldset>
		<?php
			echo $this->Form->input('name', array('label' => 'Meno'));
			echo $this->Form->input('surname', array('label' => 'Priezvisko'));
			echo $this->Form->input('email', array('label' => 'E-mail'));
			echo $this->Form->input('phone', array('label' => 'Telefónne číslo'));
			/*
			echo $this->Form->input('titles_before', array('label' => 'Tituly pred menom'));
			echo $this->Form->input('titles_after', array('label' => 'Tituly za menom'));
			 */
			$monthNames = array(
				1 => 'Január', 2 => 'Február', 3 => 'Marec', 4 => 'Apríl', 5 => 'Máj', 6 => 'Jún',
				7 => 'Júl', 8 => 'August', 9 => 'September', 10 => 'Október', 11 => 'November', 12 => 'December'
			);

			echo $this->Form->input('birthday_select', array('label' => 'Dátum narodenia', 'class' => 'datetime',
				'type' => 'date', 'minYear' => 1900, 'maxYear' => date('Y'), 'dateFormat' => 'DMY', 'monthNames' => $monthNames, 'div' => array('class' => 'input text datum')));

			echo '<div class="checkbox not_available"><label for="PersonBirthdateNotAvailable">Nie je k dispozícii</label>';
			echo $this->Form->checkbox('birthdate_not_available', array('onclick' => 'disableEnableDate();'));
			echo '</div>';
			echo '<div class="clear"></div>';

			$options = array(
				0 => 'Vyberte typ'
			);

			foreach ($personTypeList as $personType) {
				$options[$personType['PersonType']['id']] = $personType['PersonType']['title'];
			}

			echo $this->Form->input('fk_person_type_id', array('label' => 'Typ osoby', 'options' => $options, 'onchange' => 'displayParentPerson(this.value);'));

			$options = array(
				0 => 'Vyberte nadriadeného'
			);

			foreach ($personList as $person) {
				$options[$person['Person']['id']] = $person['Person']['full_name'] . ($person['PersonType']['title'] ? ' - ' . $person['PersonType']['title'] : '');
			}

			echo $this->Form->input('fk_parent_person_id', array('label' => 'Nadriadený v rámci štruktúry', 'options' => $options, 'div' => array('id' => 'ParentDiv', 'style' => 'display:none;')));
			
			echo '<script type="text/javascript">
					var PersonFkPersonTypeId = $("PersonFkPersonTypeId");
					displayParentPerson(PersonFkPersonTypeId.value);
				</script>';
			
			echo '<button name="create_user_button" class="create_user" value="1">Vytvoriť používateľské konto</button>';
			
			if (isset($createUser) && $createUser === TRUE) {
				echo $this->Form->input('User.username', array('label' => 'Používateľské meno'));
				echo $this->Form->input('User.password', array('label' => 'Heslo', 'type' => 'text', 'div' => array('class' => 'input password required')));
				echo $this->Form->hidden('create_user', array('value' => 1));
			}
		?>
		</fieldset>
	<?php echo $this->Form->end(__('Uložiť')); ?>
</div>